﻿namespace FictionsDownload.Model
{
    using FictionsDownload.DAL;
    using FictionsDownload.Migrations;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.ModelConfiguration.Conventions;
    using System.Linq;

    public class db_SQLite : DbContext
    {
        public db_SQLite(): base("name=db_SQLite")
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<db_SQLite, ConfigurationSQLite>());
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
            modelBuilder.Configurations.AddFromAssembly(typeof(db_SQLite).Assembly);
            modelBuilder.Entity<FolderModel>().HasMany(f => f.Books).WithRequired(b => b.Folder).HasForeignKey(b => b.FolderId).WillCascadeOnDelete();
            modelBuilder.Entity<BookModel>().HasMany(b=>b.Directories).WithRequired(b => b.Book).HasForeignKey(b => b.BookId).WillCascadeOnDelete();
        }
        public virtual DbSet<BookModel> Books { get; set; }
        public virtual DbSet<FolderModel> Folders { get; set; }
        public virtual DbSet<DirectoryModel> Directorys { get; set; }
        public virtual DbSet<WebFormatModel> WebFormats { get; set; }
    }

}